package com.huanxing.cloud.common.log.event;

import com.huanxing.cloud.common.core.constant.SecurityConstants;
import com.huanxing.cloud.upms.common.dto.SysLogRqDTO;
import com.huanxing.cloud.upms.common.entity.SysLoginLog;
import com.huanxing.cloud.upms.common.feign.FeignSysLogService;
import com.huanxing.cloud.upms.common.feign.FeignSysLoginLogService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author: lijx
 * @date: 2023/6/26 11:51
 **/
@Slf4j
@Component
@RequiredArgsConstructor
public class HxLogEventListener {

	private final FeignSysLogService feignSysLogService;

	private final FeignSysLoginLogService feignSysLoginLogService;

	@Async
	@EventListener(HxLogEvent.class)
	public void saveSysLog(HxLogEvent event) {
		SysLogRqDTO sysLog = event.getSysLogRqDTO();
		feignSysLogService.saveLog(sysLog, SecurityConstants.SOURCE_IN);
	}

	@Async
	@EventListener(HxLoginLogEvent.class)
	public void saveSysLoginLog(HxLoginLogEvent event) {
		SysLoginLog sysLoginLog = event.getSysLoginLog();
		feignSysLoginLogService.save(sysLoginLog, SecurityConstants.SOURCE_IN);
	}

}
